#include <iostream>
#include <vector>
using namespace std;

int skip(int n,int m){
	vector<int> dp(m + 1,100);
	dp[n] = 0;
	for(int i = n;i <= m;i++){
		for(int j = 2;j * j <= i;j++){
			if(i % j == 0){
				if(i + j <= m){
					dp[i+j] = min(dp[i] + 1,dp[i+j]);
				}
				if(i + (i / j) <= m){
					dp[i+i/j] = min(dp[i] + 1,dp[i+i/j]);
				}
			}
			
		}
	}
	if(dp[m] == 100) return -1;
	return dp[m];
}

int main(){
	int n,m;
	cin>>n>>m;
	int res = skip(n,m);
	cout<<res<<endl;
} 
